home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / scandep.zip / SCANDEP.TXT < prev   
Text File  |  1997-06-26  |  22KB  |  579 lines

  1.                                   SCANDEP 1.00
  2.                                   ------------
  3.  
  4.         Purpose
  5.         -------
  6.         SCANDEP is a C/C++ programmer's utility to generate dependency
  7.         lists for one or more source files.  Dependencies are displayed
  8.         in either a hierarchical format or formats suitable for
  9.         makefiles.  SCANDEP was developed with and for the Microsoft
  10.         compiler (MSVC), but I know of no reason why it wouldn't work
  11.         with source for any standard C/C++ compiler.
  12.  
  13.         SCANDEP is a DOS command-line utility, but of course it can be
  14.         run in a DOS window under Windows or OS/2.
  15.  
  16.         If you don't know what a dependency list is, or what a dependent
  17.         file is, then you probably don't need this program.
  18.  
  19.  
  20.         Why?
  21.         ----
  22.         I recently needed a DOS program to generate makefile-suitable
  23.         lists of file dependencies for a large number of C++ source
  24.         files and assumed that it would be pretty easy to find one on
  25.         CompuServe or the Internet.  I did find several, but none worked
  26.         quite right.  Either they missed files for no obvious reason, or
  27.         they automatically included all of the "system" headers (like
  28.         stdio.h), or they didn't recognize that some of the #include
  29.         directives were commented out.
  30.  
  31.         Particularly troubling was that most of the ones I found did not
  32.         search for included files in the same way that C/C++ compilers
  33.         do.  For example, MSVC never explicitly searches the current
  34.         directory for an include file.  It looks in the directory of the
  35.         file that does the including (and of the file that included
  36.         that, etc.), and this may very well result in a search of the
  37.         current directory, but it never looks in the current directory
  38.         unless one of its "includers" lives there.  Most of the
  39.         dependency generators I tried didn't understand this, or, more
  40.         generally, the basic search pattern for include files.
  41.  
  42.         Anyway, this simple program is the result.  It may or may not be
  43.         free of bugs, but it does attempt to follow the search patterns
  44.         of MSVC (the only C/C++ compiler I'm familiar with); it
  45.         understand comments; and it's flexible about the handling of
  46.         system includes.
  47.  
  48.  
  49.         Output formats
  50.         --------------
  51.         SCANDEP can generate its output in three formats; we'll describe
  52.         these before we begin with SCANDEP's syntax and options.
  53.  
  54.         Let's assume that you have asked SCANDEP to scan the source file
  55.         PROJECT.CPP and that we have the following project file
  56.         structure:
  57.  
  58.             PROJECT.CPP:
  59.             #include "project.h"
  60.             #include "common.h"
  61.  
  62.             PROJECT.H:
  63.             #include "stuff.h"
  64.  
  65.             STUFF.H:
  66.             #include "common.h"
  67.  
  68.             COMMON.H:
  69.             // no includes
  70.  
  71.         The default SCANDEP output format generates a makefile-suitable
  72.         description block like this:
  73.  
  74.             project.obj: project.cpp \
  75.                 project.h \
  76.                 stuff.h \
  77.                 common.h
  78.  
  79.         As you can see, this block shows that the object file
  80.         PROJECT.OBJ is dependent on the source files PROJECT.CPP,
  81.         PROJECT.H, STUFF.H, and COMMON.H.  The block is ready for the
  82.         addition of the necessary build commands to create PROJECT.OBJ.
  83.  
  84.         The second format conforms with that used by MSVC in makefiles
  85.         that it creates.  MSVC users will have noted that the
  86.         description blocks in MSVC-generated makefiles do not explicitly
  87.         list all of the dependencies.  Instead, the dependencies
  88.         (excluding the primary source file) are assigned to a macro, and
  89.         the macro is used in the description block.  SCANDEP can
  90.         generate output in this format; it would look like this:
  91.  
  92.             PROJECT_DEP = project.h \
  93.                 stuff.h \
  94.                 common.h
  95.  
  96.             project.obj: project.cpp $(PROJECT_DEP)
  97.  
  98.         The third format is not for makefiles.  It simply displays the
  99.         include file structure in hierarchical format:
  100.  
  101.             c:\project\project.cpp
  102.                c:\project\project.h
  103.                   c:\project\stuff.h
  104.                      c:\project\common.h
  105.                c:\project\common.h
  106.  
  107.         This clearly shows that PROJECT.CPP #includes PROJECT.H and
  108.         COMMON.H; that PROJECT.H #includes STUFF.H; and that STUFF.H
  109.         #includes COMMON.H.  Note that, unlike the makefile blocks,
  110.         files can appear more than once (as COMMON.H does), and that
  111.         absolute paths are shown.
  112.  
  113.  
  114.         Syntax
  115.         ------
  116.         The basic syntax is:
  117.  
  118.             scandep [options] {target[=ext]}
  119.  
  120.         The targets are the source files that you want to scan;
  121.         the options affect how SCANDEP operates.
  122.  
  123.         If there are many targets or options, the command line may
  124.         become too long, or inconvenient to type.  In that case, you
  125.         can store the targets and/or options in a text file called
  126.         a "response file" and run SCANDEP in this way:
  127.  
  128.             scandep @response-file
  129.  
  130.         We'll describe response files more fully below.
  131.  
  132.  
  133.         Specifying targets
  134.         ------------------
  135.         Targets are the source files that you wish to scan.  They
  136.         must be C/C++ source files or MSVC-compatible resource files
  137.         (.RC extension).  You must specify at least one target, or
  138.         SCANDEP will complain that it has nothing to do.
  139.  
  140.         The simplest usage of SCANDEP just specifies a single target:
  141.  
  142.             scandep myfile.cpp
  143.  
  144.         This will scan the target MYFILE.CPP for dependencies (i.e.,
  145.         #include files) and create a makefile-suitable dependency
  146.         list.  It might look like this:
  147.  
  148.             myfile.obj: myfile.cpp \
  149.                 myfile.h \
  150.                 common.h \
  151.                 stdafx.h
  152.  
  153.         Note that SCANDEP has assumed that the ultimate target file is
  154.         MYFILE.OBJ (created from MYFILE.CPP); it has actually created
  155.         a dependency list for MYFILE.OBJ rather than MYFILE.CPP.
  156.  
  157.         Of course, you can redirect SCANDEP's output to a text file for
  158.         editing and/or merging into makefiles.  For example:
  159.  
  160.             scandep myfile.cpp > myfile.dep
  161.  
  162.         You can specify multiple targets, and you can use wildcards.
  163.         Paths are OK, including paths relative to the current directory.
  164.         For example:
  165.  
  166.             scandep *.cpp res\*.rc
  167.  
  168.         This will scan all *.CPP files in the current directory and all
  169.         *.RC files in the subdirectory RES.  Each target produces a
  170.         separate dependency list.
  171.  
  172.  
  173.         Specifying target extensions
  174.         ----------------------------
  175.         In the previous example, SCANDEP assumes that the makefile
  176.         target to be created for MYFILE.CPP is MYFILE.OBJ (since
  177.         MYFILE.CPP would typically be compiled to MYFILE.OBJ).  SCANDEP
  178.         recognizes three extensions:
  179.  
  180.             .CPP    -> .OBJ
  181.             .C      -> .OBJ
  182.             .RC     -> .RES
  183.  
  184.         If you have targets with any other extension, or if you want
  185.         different extensions used as the makefile target, specify
  186.         "target extensions" with your targets.  Specify the extension
  187.         for a target by following the target with an equals sign and the
  188.         new extension:
  189.  
  190.             target=ext
  191.  
  192.         For example, suppose you have C++ source files with the
  193.         extension .INL that compile to .OBJ files.  SCANDEP will not
  194.         handle these automatically because it doesn't recognize INL as a
  195.         C++ source file.  You would need to specify the extension on the
  196.         command line as follows:
  197.  
  198.             scandep myfile.inl=obj
  199.  
  200.         This would create the desired makefile target:
  201.  
  202.             myfile.obj: myfile.inl \
  203.                 ...
  204.  
  205.         Target extensions are a non-issue in hierarchical output
  206.         format because SCANDEP does not create a makefile target.
  207.  
  208.  
  209.         Options
  210.         -------
  211.         SCANDEP's options are:
  212.  
  213.           /A   Use absolute paths in dependency lists
  214.           /Ef  Set error handling mode for #include not found
  215.           /Er  Set error handling mode for recursive #include
  216.           /Et  Set error handling mode for target not found
  217.           /Ex  Set error handling mode for unknown extension
  218.           /H   Output dependencies in hierarchical format
  219.           /M   Output dependencies in MSVC format
  220.           /I   Specify additional include search path(s)
  221.           /S   Read system includes (#include <file>)
  222.           /X   Exclude named file from dependency lists
  223.           /?   Display brief help
  224.  
  225.         Options are case-insensitive (/a == /A).  They may be specified
  226.         in any order, and may precede, follow, or be mixed in with
  227.         targets.  All options are processed before any scanning
  228.         begins.
  229.  
  230.         Multiple options must be separated by spaces, i.e., "/H /S"
  231.         rather than "/H/S".
  232.  
  233.         The options are described in the following sections.
  234.  
  235.  
  236.         /A: absolute paths
  237.         ------------------
  238.         When generating dependency lists, SCANDEP uses paths relative to
  239.         the main target.  For example, suppose we have this:
  240.  
  241.             c:\one\two\myfile.cpp:
  242.             #include "myfile.h"
  243.             #include "\one\common.h"
  244.             #include "\one\two\res\resource.h"
  245.  
  246.         The dependency list would look like this:
  247.  
  248.             myfile.obj: myfile.cpp \
  249.                 myfile.h \
  250.                 ..\common.h \
  251.                 res\resource.h
  252.  
  253.         Note that all paths are relative to the directory containing the
  254.         target, MYFILE.CPP.  This allows projects to be easily moved
  255.         without requiring makefiles to be completely re-made.
  256.  
  257.         However, if you prefer absolute paths, use the /A option:
  258.  
  259.             scandep /A myfile.cpp
  260.  
  261.         This command would generate the following dependency list:
  262.  
  263.             myfile.obj: c:\one\two\myfile.cpp \
  264.                 c:\one\two\myfile.h \
  265.                 c:\one\common.h \
  266.                 c:\one\two\res\resource.h
  267.  
  268.         Regardless of the presence or absence of /A, SCANDEP
  269.         always uses absolute paths in three cases:
  270.  
  271.           1. For any dependent that is not located on the same drive as
  272.              the target.
  273.  
  274.           2. For dependents that descend from a different first-level
  275.              directory than the target.
  276.  
  277.           3. For system includes, i.e., those enclosed in <>:
  278.  
  279.                 #include <stdio.h>
  280.  
  281.              Note that system includes are only scanned if the /S option
  282.              is present.
  283.  
  284.         An example of case 2: if MYFILE.CPP also #included
  285.         c:\x\y\some.h, the list would be:
  286.  
  287.             myfile.obj: myfile.cpp \
  288.                 myfile.h \
  289.                 ..\common.h \
  290.                 res\resource.h \
  291.                 c:\x\y\some.h
  292.  
  293.         As you can see, the full path from the root is specified for
  294.         SOME.H; it is not relative to the location of MYFILE.CPP.  This
  295.         is because SOME.H lies below the first-level directory X rather
  296.         than MYFILE's first-level directory ONE.
  297.  
  298.  
  299.         /E: error handling modes
  300.         ------------------------
  301.         Certain potentially recoverable errors can occur when scanning
  302.         for dependencies. These are:
  303.  
  304.             - Target file not found.
  305.  
  306.             - #include file not found.
  307.  
  308.             - Unknown target extensions (extension not .C, .CPP, or .RC,
  309.               and no target extension provided).
  310.  
  311.             - Recursive includes (a file that directly or indirectly
  312.               #includes itself).
  313.  
  314.         You can control how SCANDEP responds to each of these situations
  315.         using the /E option.  /E is followed by a single letter
  316.         specifying an error condition:
  317.  
  318.             /Ef: include not found
  319.             /Er: recursive include
  320.             /Et: target not found
  321.             /Ex: unknown extension
  322.  
  323.         Following the error condition is a single digit, which must be
  324.         0, 1, 2, or 3 (e.g., /Er2).  These mean:
  325.  
  326.             0: ignore the error
  327.             1: report the error but continue processing
  328.             2: report the error and exit
  329.             3: report the error, display a list of active source files,
  330.                and exit
  331.  
  332.         The default settings are:
  333.  
  334.             /Ef2 (error exit on #include not found)
  335.             /Er1 (report recursive includes but continue)
  336.             /Et2 (error exit on target not found)
  337.             /Ex2 (error exit on unknown extensions)
  338.  
  339.         Mode 3 affects /Ef and /Er only.  For /Et and /Ex, mode 3 is the
  340.         same as mode 2.
  341.  
  342.  
  343.         /H: use hierarchical output format
  344.         ----------------------------------
  345.         Adding the /H option causes SCANDEP to generate its output in
  346.         the hierarchical format described above:
  347.  
  348.             scandep /h myfile.cpp
  349.  
  350.         When /H is specified, /A has no effect (the output always uses
  351.         absolute paths), and unknown target extensions are of no
  352.         significance.  /H overrides /M; if both are specified, the
  353.         output will be in hierarchical format.
  354.  
  355.  
  356.         /I: specify include path
  357.         ------------------------
  358.         When searching for #included files, SCANDEP follows the standard
  359.         MSVC search pattern (see online help for #include).  This
  360.         includes the directories containing all "parent" files of the
  361.         file being included and the directories specified by the
  362.         environment variable INCLUDE.
  363.  
  364.         MSVC provides the /I option, which allows you to specify
  365.         additional directories search; SCANDEP provides a very similar
  366.         option.  To use it, just specify /I followed by a directory
  367.         name:
  368.  
  369.             scandep /I\projects\common myfile.cpp
  370.  
  371.         To specify multiple directories, either use multiple /I options
  372.         or use a PATH-like specification, separating directories with
  373.         semicolons:
  374.  
  375.             scandep /I\projects\common /I\toolkit\include ...
  376.             scandep /I\projects\common;\toolkit\include ...
  377.  
  378.         In either case, SCANDEP adds \PROJECTS\COMMON and
  379.         \TOOLKIT\INCLUDE to its list of searchable directories.  These
  380.         directories are searched before the INCLUDE variable
  381.         directories, by the way.
  382.  
  383.         MSVC users: note that, unlike MSVC, there is no space between /I
  384.         and the directory name.
  385.  
  386.  
  387.         /M: use MSVC format
  388.         -------------------
  389.         Adding the /M option causes SCANDEP to generate dependencies in
  390.         "MSVC format" as described above:
  391.  
  392.             scandep /m myfile.cpp
  393.  
  394.         In this format, dependencies are assigned to makefile macros,
  395.         and the macros are used in the description blocks.
  396.  
  397.  
  398.         /S: scan system includes
  399.         ------------------------
  400.         Normally, SCANDEP ignores the "system" includes, i.e., include
  401.         files specified with <>:
  402.  
  403.             #include "myfile.h"  // SCANDEP scans this...
  404.             #include <stdio.h>   // ...but not this
  405.  
  406.         This is because system headers rarely change and are typically
  407.         not included in makefiles.
  408.  
  409.         However, you can force SCANDEP to scan the system headers by
  410.         using the /S option:
  411.  
  412.             scandep /s myfile.cpp
  413.  
  414.  
  415.         /X: exclude dependents
  416.         ----------------------
  417.         Occasionally you may wish to exclude specific dependents from
  418.         dependency lists.  Do this with the /X option, which is followed
  419.         by a filename.  For example:
  420.  
  421.             scandep myfile.cpp /Xresource.h
  422.  
  423.         This command would omit RESOURCE.H from all dependency lists.
  424.  
  425.         Note that SCANDEP doesn't scan excluded files for dependencies.
  426.         In other words, both the excluded file and its dependents are
  427.         omitted from the output.
  428.  
  429.         The filename as specified must exactly match the filename
  430.         provided in the #include directive.  If you've used
  431.         "/Xresource.h", then SCANDEP will recognize and exclude:
  432.  
  433.             #include "resource.h"
  434.  
  435.         but not:
  436.  
  437.             #include "c:\myfile\resource.h"
  438.  
  439.         /X excludes dependents (include files), not targets.  If your
  440.         target is *.C, all C source files will be scanned; you can't
  441.         exclude a specific C source file by using, for example,
  442.         "/Xuseless.c".
  443.  
  444.  
  445.         /?: display brief help
  446.         ----------------------
  447.         The /? option displays a screen comtaining a brief summary of
  448.         SCANDEP's syntax and options.
  449.  
  450.             scandep /?
  451.  
  452.         If /? is used, all other options and targets are ignored;
  453.         SCANDEP displays the help screen and terminates.
  454.  
  455.  
  456.         Using response files
  457.         --------------------
  458.         If the command line grows too long, or if you want to run
  459.         SCANDEP regularly on a particular project, you can use a
  460.         response file.
  461.  
  462.         To create a response file, use your regular text editor to
  463.         create a text file containing any number of targets and/or
  464.         options.  Lines in the response file may be empty; they may
  465.         contain one target or option; or they may contain multiple
  466.         targets and/or options (just like the command line).  However,
  467.         individual lines are limited to 500 characters.
  468.  
  469.         A response file might look like this:
  470.  
  471.             myfile.cpp
  472.             fileiter.cpp
  473.             sources.cpp
  474.             res\resource.cpp
  475.             common.cpp
  476.             /Xresource.h /S
  477.             /I\library\include
  478.             /M
  479.  
  480.         To use the response file, simply put its name on the command
  481.         line follwing an @, e.g.:
  482.  
  483.             scandep @scandep.rf
  484.  
  485.         It's perfectly OK to mix command line options and targets with a
  486.         response file:
  487.  
  488.             scandep /S target.c @scandep.rf
  489.  
  490.         You can use multiple response files, but they can't be nested.
  491.  
  492.  
  493.         Errorlevels
  494.         -----------
  495.         SCANDEP returns one of the following DOS errorlevels on
  496.         completion:
  497.  
  498.             0   no errors
  499.             1   recursive header found (/Er2 mode)
  500.             2   unknown target extension (/Ex2)
  501.             3   include file not found (/Ef2)
  502.             4   include file could not be opened
  503.             5   target not found (/Et2)
  504.             254 system exception (out of memory, file I/O error)
  505.             255 usage error; response file not found; response file line
  506.                 too long
  507.  
  508.  
  509.         Implementation limits
  510.         ---------------------
  511.         1. Source files are assumed to be text files consisting of lines
  512.         no longer than 2000 characters.  Excess characters are
  513.         discarded.
  514.  
  515.         2. Response files are assumed to be text files consisting of
  516.         lines no longer than 500 characters.  Longer lines will generate
  517.         an error.
  518.  
  519.         3. SCANDEP does not recognize the RCINCLUDE directive in MSC
  520.         resource files.
  521.  
  522.         4. SCANDEP is a DOS program and it can run out of memory if many
  523.         targets are specified, if the dependency lists are extremely
  524.         large or if not much memory is available.  Try reducing the
  525.         number of targets per run.
  526.  
  527.  
  528.         Problems/comments/suggestions
  529.         -----------------------------
  530.         Please report any problems and send any comments or suggestions
  531.         to me at the email addresses below.
  532.  
  533.  
  534.         Release history
  535.         ---------------
  536.         6/26/97 v1.00: initial release
  537.  
  538.  
  539.         Copyright/License/Warranty
  540.         --------------------------
  541.         This document and the program file SCANDEP.EXE ("the software")
  542.         are copyrighted by the author.  If you are an individual, the
  543.         copyright owner hereby licenses you to use the software, make
  544.         as many copies of the software and documentation as you wish,
  545.         give such copies to anyone, and distribute the software and
  546.         documentation via electronic means.  There is no charge for any
  547.         of the above.
  548.  
  549.         However, you are specifically prohibited from charging, or
  550.         requesting donations, for any such copies, however made; and
  551.         from distributing the software and/or documentation with
  552.         commercial products without prior permission.  An exception is
  553.         granted to not-for-profit user's groups, which are authorized to
  554.         charge a small fee (not to exceed $7) for materials, handling,
  555.         postage, and general overhead.
  556.  
  557.         Businesses, institutions, and governmental entities must obtain
  558.         a specific license agreement from The Cove Software Group in
  559.         order to use the software.
  560.  
  561.         No copy of the software may be distributed or given away without
  562.         this document; and this notice must not be removed.
  563.  
  564.         There is no warranty of any kind, and the copyright owner is not
  565.         liable for damages of any kind.  By using this free software,
  566.         you agree to this.
  567.  
  568.         The software and documentation are:
  569.  
  570.                              Copyright (C) 1997 by
  571.                              Christopher J. Dunford
  572.                             The Cove Software Group
  573.                                10551 Rivulet Row
  574.                             Columbia, Maryland 21044
  575.  
  576.                               Tel: (410) 992-9371
  577.                              CompuServe: 76703,2002
  578.                           email: cd@cis.compuserve.com
  579.